﻿using System.Collections.Generic;
using System.Linq;
using AZROLESLib;
using AzManContrib.MVC.Initialization;

namespace AzManContrib.MVC
{
// ReSharper disable InconsistentNaming
    public static class IAzOperationsExtensions
// ReSharper restore InconsistentNaming
    {
        public static IEnumerable<IAzOperation> AsEnumerable(this IAzOperations operations)
        {
            return operations.Cast<IAzOperation>().ToList();
        }

        public static IAzOperation FindByName(this IAzOperations operations, string name)
        {
            OperationList operationList = operations as OperationList;
            if (operationList != null)
                return (operationList).FindByName(name);

            return AsEnumerable(operations).FirstOrDefault(op => op.Name == name);
        }
    }
}